package com.itcms.core.domain;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.itcms.core.domain.NodeExt.NodeExtId;

@Entity
@Table(name = "cms_node_ext")
@IdClass(NodeExtId.class)
public class NodeExt implements java.io.Serializable {
	private static final long serialVersionUID = 1L;

	public NodeExt() {
	}

	public NodeExt(Node node, Node nodeExt) {
		this.node = node;
		this.nodeExt = nodeExt;
	}

	@Id
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "f_node_id", nullable = false)
	private Node node;

	@Id
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "f_node_ext_id", nullable = false)
	private Node nodeExt;


	public Node getNode() {
		return node;
	}

	public void setNode(Node node) {
		this.node = node;
	}

	public Node getNodeExt() {
		return nodeExt;
	}

	public void setNodeExt(Node nodeExt) {
		this.nodeExt = nodeExt;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((nodeExt == null) ? 0 : nodeExt.hashCode());
		result = prime * result + ((node == null) ? 0 : node.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NodeExt other = (NodeExt) obj;
		if (nodeExt == null) {
			if (other.nodeExt != null)
				return false;
		} else if (!nodeExt.equals(other.nodeExt))
			return false;
		if (node == null) {
			if (other.node != null)
				return false;
		} else if (!node.equals(other.node))
			return false;
		return true;
	}


	public static class NodeExtId implements Serializable {
		private static final long serialVersionUID = 1L;

		Integer node;
		Integer nodeExt;

		public NodeExtId() {
		}

		public NodeExtId(Integer node, Integer nodeExt) {
			this.node = node;
			this.nodeExt = nodeExt;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result
					+ ((nodeExt == null) ? 0 : nodeExt.hashCode());
			result = prime * result + ((node == null) ? 0 : node.hashCode());
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			NodeExtId other = (NodeExtId) obj;
			if (nodeExt == null) {
				if (other.nodeExt != null)
					return false;
			} else if (!nodeExt.equals(other.nodeExt))
				return false;
			if (node == null) {
				if (other.node != null)
					return false;
			} else if (!node.equals(other.node))
				return false;
			return true;
		}
	}
}
